package com.demo.design.behavioral.mediator.impl;

import com.demo.design.behavioral.mediator.Colleague;
import com.demo.design.behavioral.mediator.Mediator;

import java.util.ArrayList;
import java.util.List;

public class RealMediator implements Mediator {
    private List<Colleague> colleagueList = new ArrayList<>();

    @Override
    public void register(Colleague colleague) {
        for (Colleague self : colleagueList) {
            if (colleague == self) {
                System.err.println("该同事已注册");
                return;
            }
        }
        colleagueList.add(colleague);
    }

    @Override
    public void transpond(Colleague sender, String meg) {
        for (Colleague colleague : colleagueList) {
            if (colleague != sender) {
                colleague.getNotice(meg);
            }
        }
    }
}
